package com.jinlia.show.modules.wxapp.controller;

import com.jinlia.show.common.core.utils.UserInfoUtils;
import com.jinlia.show.modules.base.constant.DeliveryTypeEnum;
import com.jinlia.show.modules.base.system.entity.DeliveryOrder;
import com.jinlia.show.modules.base.system.service.DeliveryOrderMapperService;
import com.jinlia.show.modules.base.wxapp.entity.User;
import com.jinlia.show.modules.base.model.po.UserPO;
import com.jinlia.show.modules.base.wxapp.service.UserMapperService;
import com.jinlia.show.modules.wxapp.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserMapperService userMapperService;
    @Autowired
    private DeliveryOrderMapperService deliveryOrderMapperService;

    /**
     * 用户头像
     *
     * @param user
     * @return
     */
    @PostMapping(value = "/update")
    private User avatar(@RequestBody User user) {
        return userService.updateById(user);
    }

    @GetMapping("{{id}}")
    public ResponseEntity<User> getById(@PathVariable(value = "id") Long id) {
        return ResponseEntity.ok(userMapperService.getById(id));
    }

    @GetMapping("get/last/deliveryOrder")
    public DeliveryOrder getLastOne() {
        DeliveryOrder one = deliveryOrderMapperService
                .lambdaQuery()
                .orderByDesc(DeliveryOrder::getCreateTime) //创建时间降序
                .last("limit 1")
                .one();
        return one;
    }
}
